home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / src / motif.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-11  |  6.3 KB  |  264 lines

  1. /* motif.c-- stuff for support for mwm hints
  2.  * 
  3.  *  Window Maker window manager
  4.  * 
  5.  *  Copyright (c) 1998, 1999 Alfredo K. Kojima
  6.  * 
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  20.  *  USA.
  21.  */
  22.  
  23.  
  24. #include "wconfig.h"
  25.  
  26. #ifdef MWM_HINTS
  27.  
  28. #include <X11/Xlib.h>
  29. #include <X11/Xutil.h>
  30.  
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <string.h>
  34.  
  35.  
  36. #include "WindowMaker.h"
  37.  
  38. #include "wcore.h"
  39. #include "framewin.h"
  40. #include "window.h"
  41. #include "properties.h"
  42. #include "icon.h"
  43. #include "client.h"
  44. #include "funcs.h"
  45.  
  46. #include "motif.h"
  47.  
  48.  
  49. /* Motif window hints */
  50. #define MWM_HINTS_FUNCTIONS           (1L << 0)
  51. #define MWM_HINTS_DECORATIONS         (1L << 1)
  52.  
  53. /* bit definitions for MwmHints.functions */
  54. #define MWM_FUNC_ALL            (1L << 0)
  55. #define MWM_FUNC_RESIZE         (1L << 1)
  56. #define MWM_FUNC_MOVE           (1L << 2)
  57. #define MWM_FUNC_MINIMIZE       (1L << 3)
  58. #define MWM_FUNC_MAXIMIZE       (1L << 4)
  59. #define MWM_FUNC_CLOSE          (1L << 5)
  60.  
  61. /* bit definitions for MwmHints.decorations */
  62. #define MWM_DECOR_ALL                 (1L << 0)
  63. #define MWM_DECOR_BORDER              (1L << 1)
  64. #define MWM_DECOR_RESIZEH             (1L << 2)
  65. #define MWM_DECOR_TITLE               (1L << 3)
  66. #define MWM_DECOR_MENU                (1L << 4)
  67. #define MWM_DECOR_MINIMIZE            (1L << 5)
  68. #define MWM_DECOR_MAXIMIZE            (1L << 6)
  69.  
  70. #define PROP_MWM_HINTS_ELEMENTS       5
  71.  
  72. /* Motif  window hints */
  73. typedef struct {
  74.     long flags;
  75.     long functions;
  76.     long decorations;
  77.     long inputMode;
  78.     long unknown;
  79. } MWMHints;
  80.  
  81. static Atom _XA_MOTIF_WM_HINTS;
  82.  
  83.  
  84.  
  85. static void 
  86. setupMWMHints(WWindow *wwin, MWMHints *mwm_hints)
  87. {
  88.     /* 
  89.      * We will ignore all decoration hints that have an equivalent as
  90.      * functions, because wmaker does not distinguish decoration hints
  91.      */
  92.     
  93.     if (mwm_hints->flags & MWM_HINTS_DECORATIONS) {
  94. # ifdef DEBUG
  95.     fprintf(stderr,"has decor hints [ ");
  96. # endif
  97.     WSETUFLAG(wwin, no_titlebar, 1);
  98.     WSETUFLAG(wwin, no_close_button, 1);
  99.     WSETUFLAG(wwin, no_miniaturize_button, 1);
  100.     WSETUFLAG(wwin, no_resizebar, 1);
  101.     
  102.     if (mwm_hints->decorations & MWM_DECOR_ALL) {
  103. # ifdef DEBUG
  104.         fprintf(stderr,"ALL ");
  105. # endif
  106.         WSETUFLAG(wwin, no_titlebar, 0);
  107.         WSETUFLAG(wwin, no_close_button, 0);
  108.         WSETUFLAG(wwin, no_closable, 0);
  109.         WSETUFLAG(wwin, no_miniaturize_button, 0);
  110.         WSETUFLAG(wwin, no_miniaturizable, 0);
  111.         WSETUFLAG(wwin, no_resizebar, 0);
  112.         WSETUFLAG(wwin, no_resizable, 0);
  113.     }
  114. /*
  115.     if (mwm_hints->decorations & MWM_DECOR_BORDER) {
  116. # ifdef DEBUG
  117.         fprintf(stderr,"(BORDER) ");
  118. # endif
  119.     }
  120.  */
  121.  
  122.     if (mwm_hints->decorations & MWM_DECOR_RESIZEH) {
  123. # ifdef DEBUG
  124.         fprintf(stderr,"RESIZEH ");
  125. # endif
  126.         WSETUFLAG(wwin, no_resizebar, 0);
  127.     }
  128.  
  129.     if (mwm_hints->decorations & MWM_DECOR_TITLE) {
  130. # ifdef DEBUG
  131.         fprintf(stderr,"TITLE+close ");
  132. # endif
  133.         WSETUFLAG(wwin, no_titlebar, 0);
  134.         WSETUFLAG(wwin, no_close_button, 0);
  135.         WSETUFLAG(wwin, no_closable, 0);
  136.     }
  137. /*
  138.     if (mwm_hints->decorations & MWM_DECOR_MENU) {
  139. # ifdef DEBUG
  140.         fprintf(stderr,"(MENU) ");
  141. # endif
  142.     }
  143.  */
  144.  
  145.     if (mwm_hints->decorations & MWM_DECOR_MINIMIZE) {
  146. # ifdef DEBUG
  147.         fprintf(stderr,"MINIMIZE ");
  148. # endif
  149.         WSETUFLAG(wwin, no_miniaturize_button, 0);
  150.         WSETUFLAG(wwin, no_miniaturizable, 0);
  151.     }
  152. /*
  153.     if (mwm_hints->decorations & MWM_DECOR_MAXIMIZE) {
  154. # ifdef DEBUG
  155.         fprintf(stderr,"(MAXIMIZE) ");
  156. # endif
  157.     }
  158.  */
  159. # ifdef DEBUG
  160.     fprintf(stderr,"]\n");
  161. # endif
  162.     }
  163.  
  164.  
  165.     if (mwm_hints->flags & MWM_HINTS_FUNCTIONS) {
  166. # ifdef DEBUG
  167.     fprintf(stderr,"has function hints [ ");
  168. # endif
  169.     WSETUFLAG(wwin, no_closable, 1);
  170.     WSETUFLAG(wwin, no_miniaturizable, 1);
  171.     WSETUFLAG(wwin, no_resizable, 1);
  172.     
  173.     if (mwm_hints->functions & MWM_FUNC_ALL) {
  174. # ifdef DEBUG 
  175.         fprintf(stderr,"ALL ");
  176. # endif
  177.         WSETUFLAG(wwin, no_closable, 0);
  178.         WSETUFLAG(wwin, no_miniaturizable, 0);
  179.         WSETUFLAG(wwin, no_resizable, 0);
  180.     }
  181.     if (mwm_hints->functions & MWM_FUNC_RESIZE) {
  182. # ifdef DEBUG 
  183.         fprintf(stderr,"RESIZE ");
  184. # endif
  185.         WSETUFLAG(wwin, no_resizable, 0);
  186.     }
  187.     /*
  188.     if (mwm_hints->functions & MWM_FUNC_MOVE) {
  189. # ifdef DEBUG 
  190.         fprintf(stderr,"(MOVE) ");
  191. # endif
  192.     }
  193.      */
  194.     if (mwm_hints->functions & MWM_FUNC_MINIMIZE) {
  195. # ifdef DEBUG 
  196.         fprintf(stderr,"MINIMIZE ");
  197. # endif
  198.         WSETUFLAG(wwin, no_miniaturizable, 0);
  199.     }
  200.     if (mwm_hints->functions & MWM_FUNC_MAXIMIZE) {
  201. # ifdef DEBUG 
  202.         fprintf(stderr,"MAXIMIZE ");
  203.         /* a window must be resizable to be maximizable */
  204.         WSETUFLAG(wwin, no_resizable, 0);
  205. # endif
  206.     }
  207.     if (mwm_hints->functions & MWM_FUNC_CLOSE) {
  208. # ifdef DEBUG 
  209.         fprintf(stderr,"CLOSE ");
  210. # endif
  211.         WSETUFLAG(wwin, no_closable, 0);
  212.     }
  213. # ifdef DEBUG 
  214.     fprintf(stderr,"]\n");
  215. # endif
  216.     }
  217. }
  218.  
  219.  
  220. static int
  221. getMWMHints(Window window, MWMHints *mwmhints)
  222. {
  223.     unsigned long *data;
  224.     int count;
  225.  
  226.     if (!_XA_MOTIF_WM_HINTS) {
  227.     _XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
  228.     }
  229.  
  230.     data = (unsigned long*)PropGetCheckProperty(window, _XA_MOTIF_WM_HINTS,
  231.                         _XA_MOTIF_WM_HINTS, 32,
  232.                         0, &count);
  233.  
  234.     if (!data)
  235.     return 0;
  236.  
  237.     if (count >= 4) {
  238.         mwmhints->flags = data[0];
  239.        mwmhints->functions = data[1];
  240.        mwmhints->decorations = data[2];
  241.         mwmhints->inputMode = data[3];
  242.     if (count > 5)
  243.         mwmhints->unknown = data[4];
  244.     }
  245.     XFree(data);
  246.  
  247.     return 1;
  248. }
  249.  
  250.  
  251. void
  252. wMWMCheckClientHints(WWindow *wwin)
  253. {
  254.     MWMHints hints;
  255.     
  256.     if (getMWMHints(wwin->client_win, &hints)) {
  257.     setupMWMHints(wwin, &hints);
  258.     }
  259. }
  260.  
  261.  
  262.  
  263. #endif /* MWM_HINTS */
  264.